<template>
  <div class="facelogin">
    <div style="top:50%;padding:20px;">
      <img class="img1" src="../../assets/img/Bitmap.png" alt>
      <Form ref="identityForm" :model="identityForm">
        <FormItem prop="cerno" :rules="validator.cerno" :maxlength="18">
          <Input
            type="text"
            v-model="identityForm.cerno"
            placeholder="请输入身份证号码"
            class="login_input-user"
          />
        </FormItem>
        <FormItem>
          <Button
            type="primary"
            style="height:1.75rem;font-size:16px;"
            long
            @click="handleSubmit()"
          >进入扫脸登录</Button>
        </FormItem>
      </Form>
    </div>
    <div>
      <MyFooter/>
    </div>
  </div>
</template>

<script>
import MyFooter from "../../components/MyFooter.vue";
import request from "../../utils/request.js";
import validator from "../../utils/validatorUtil.js";
export default {
  data() {
    return {
      identityForm: {
        cerno: ""
      },
      validator
    };
  },
  methods: {
    handleSubmit() {
      this.$refs["identityForm"].validate(valid => {
        if (valid) {
          request
            .get("/interface//out/wechat/identityLogin.do", {
              cerno: this.identityForm.cerno
            })
            .then(response => {
              if (response.data.result === "error") {
                this.$ErrorAlert(response.data.message);
              } else {
                let url = "https://iauth.wecity.qq.com/new/cgi-bin/auth.php";
                let params = {};
                params.appid = response.data.data.appid;
                params.redirect = response.data.data.redirect;
                params.sceneID = response.data.data.sceneID;
                params.signature = response.data.data.signature;
                params.out_trade_no = response.data.data.out_trade_no;
                params.out_extra = this.$route.query.toPath;
                // alert(params.out_extra)
                params.type = response.data.data.type;
                params.uid = response.data.data.uid;
                params.ID = response.data.data.ID;
                params.name = response.data.data.name;
                params.pic_key = response.data.data.pic_key;

                // 请求跳转路径
                let temp = document.createElement("form");
                temp.action = url;
                temp.method = "post";
                temp.style.display = "none";
                for (let x in params) {
                  let opt = document.createElement("textarea");
                  opt.name = x;
                  opt.value = params[x];
                  temp.appendChild(opt);
                }
                document.body.appendChild(temp);
                temp.submit();
                return temp;
              }
            });
        }
      });
    }
  },
  components: {
    MyFooter
  }
};
</script>
<style>
.login_input-user .ivu-input {
  height: 1.75rem;
  background: url(../../assets/img/login-ico1.png) no-repeat 0.54rem center;
  background-size: auto 0.72rem;
  text-indent: 1.3rem;
  font-size: 14px;
}
</style>
<style scoped>
.facelogin {
  overflow: hidden;
}
.facelogin .img1 {
  display: block;
  margin: 2rem auto;
}
</style>
